package examSchedule;

import java.util.List;
import java.util.Map.Entry;
import java.util.Vector;

import cpsc433.ExamSchedulePredicates;
import cpsc433.Pair;
import cpsc433.Predicate.ParamType;

import predicate.*;

public class Solution implements ExamSchedulePredicates{

	private Environment env;
	private List<Pair<Session, Lecture>> schedule;
	private boolean solved;
	private int goodNess;
	private int numberOfNode = 0;
	private int numberOfNodeFinal = 0;
	private long time = 0;

	public Solution(String string) {
		solved = false;
	}

	public Solution(String name, Environment environment) {
		env = environment;
		solved = false;
	}

	public String getName() {
		// TODO Auto-generated method stub
		return null;
	}

	public String isSolved() {
		String toReturn = "";
		if(solved) {
			toReturn = "yes";
		} else {
			toReturn = "no";
		}
		return toReturn;
	}

	public String getGoodness() {
		return "1 / " + goodNess;
	}

	public void setGoodness(int goodNess) {
		this.goodNess = goodNess;
	}

	public void setNumberOfNodeViewed(int number) {
		numberOfNode = number;
	}

	public void setNumberOfNodeViewedFinal(int number) {
		numberOfNodeFinal = number;
	}

	public Environment getEnv() {
		return env;
	}

	public void setEnv(Environment env) {
		this.env = env;
	}

	public void setTime(long time) {
		this.time = time;
	}

	public String toString()
	{
		String toReturn = "";
		//toReturn += "\n"   + env.instructorToString();
		//toReturn += "\n" + env.courseToString();
		//toReturn += "\n" + env.lectureToString();
		//toReturn += "\n" + env.studentToString();
		//toReturn += "\n" + env.dayToString();
		//toReturn += "\n" + env.roomToString();
		//toReturn += "\n" + env.sessionToString();
		toReturn += assignToString();
		toReturn += "\n// " + env.listInstructor.size() + " Instructor(s), " + 
				env.listCourse.size() + " Course(s), " +
				env.listLecture.size() + " Lecture(s), " +
				env.listStudents.size() + " Student(s), " +
				env.listSession.size() + " Session(s), " + 
				env.listRoom.size() + " Room(s), " +
				env.listDay.size() + " Day(s).";
		toReturn += "\n// Solved ?: " + isSolved();
		toReturn += "\n// Penalities: " + goodNess;
		toReturn += "\n// Number of node viewed: " + numberOfNode;
		toReturn += "\n// Time (ms): " + time;
		toReturn += "\n// Number of node viewed at the end: " + numberOfNodeFinal;

		return toReturn;
	}

	public void setSchedule(List<Pair<Session, Lecture>> currentSchedule) {
		this.schedule = currentSchedule;
	}

	public String assignToString() {
		String toReturn = "";
		if(env != null && schedule !=null) {
			for(int i = 0; i < schedule.size(); i++) {
				toReturn += "\nassign(" + schedule.get(i).getValue().getCourse().getName() +
						", "+ schedule.get(i).getValue().getName() +", " + schedule.get(i).getKey().getName() +")";
			}
		}
		return toReturn;
	}

	public void setSolved(boolean solved) {
		this.solved = solved;
	}

	@Override
	public void a_student(String p) {
		env.a_student(p);	
	}

	@Override
	public boolean e_student(String p) {
		return 		env.e_student(p);
	}

	@Override
	public void a_instructor(String p) {
		env.a_instructor(p);
	}

	@Override
	public boolean e_instructor(String p) {
		return env.e_instructor(p);
	}

	@Override
	public void a_room(String p) {
		env.a_room(p);

	}

	@Override
	public boolean e_room(String p) {
		return env.e_room(p);
	}

	@Override
	public void a_course(String p) {
		env.a_course(p);

	}

	@Override
	public boolean e_course(String p) {
		return env.e_course(p);
	}

	@Override
	public void a_session(String p) {
		env.a_session(p);

	}

	@Override
	public boolean e_session(String p) {
		// TODO Auto-generated method stub
		return env.e_session(p);
	}

	@Override
	public void a_day(String p) {
		env.a_day(p);

	}

	@Override
	public boolean e_day(String p) {
		// TODO Auto-generated method stub
		return env.e_day(p);
	}

	@Override
	public void a_lecture(String c, String lec) {
		env.a_lecture(c, lec);

	}

	@Override
	public boolean e_lecture(String c, String lec) {
		// TODO Auto-generated method stub
		return env.e_lecture(c, lec);
	}

	@Override
	public void a_lecture(String c, String lec, String instructor, Long length) {
		env.a_lecture(c, lec, instructor, length);

	}

	@Override
	public void a_instructs(String p, String c, String l) {
		env.a_instructs(p, c, l);

	}

	@Override
	public boolean e_instructs(String p, String c, String l) {
		
		return env.e_instructs(p, c, l);
	}

	@Override
	public void a_examLength(String c, String lec, Long hours) {
		env.a_examLength(c, lec, hours);

	}

	@Override
	public boolean e_examLength(String c, String lec, Long hours) {
		// TODO Auto-generated method stub
		return env.e_examLength(c, lec, hours);
	}

	@Override
	public void a_roomAssign(String p, String room) {
		env.a_roomAssign(p, room);

	}

	@Override
	public boolean e_roomAssign(String p, String room) {
		// TODO Auto-generated method stub
		return env.e_roomAssign(p, room);
	}

	@Override
	public void a_dayAssign(String p, String day) {
		env.a_dayAssign(p, day);

	}

	@Override
	public boolean e_dayAssign(String p, String day) {
		// TODO Auto-generated method stub
		return env.e_dayAssign(p, day);
	}

	@Override
	public void a_time(String p, Long time) {
		env.a_time(p, time);

	}

	@Override
	public boolean e_time(String p, Long time) {
		// TODO Auto-generated method stub
		return env.e_time(p, time);
	}

	@Override
	public void a_length(String p, Long length) {
		env.a_length(p, length);

	}

	@Override
	public boolean e_length(String p, Long length) {
		// TODO Auto-generated method stub
		return env.e_length(p, length);
	}

	@Override
	public void a_at(String session, String day, Long time, Long length) {
		env.a_at(session, day, time, length);

	}

	@Override
	public boolean e_at(String session, String day, Long time, Long length) {
		// TODO Auto-generated method stub
		return env.e_at(session, day, time, length);
	}

	@Override
	public void a_session(String session, String room, String day, Long time,
			Long length) {
		env.a_session(session, room, day, time, length);
	}

	@Override
	public boolean e_session(String session, String room, String day,
			Long time, Long length) {
		// TODO Auto-generated method stub
		return env.e_session(session, room, day, time, length);
	}

	@Override
	public void a_enrolled(String student, String c, String l) {
		env.a_enrolled(student, c, l);

	}

	@Override
	public boolean e_enrolled(String student, String c, String l) {
		// TODO Auto-generated method stub
		return env.e_enrolled(student, c, l);
	}

	@Override
	public void a_enrolled(String student, Vector<Pair<ParamType, Object>> list) {
		env.a_enrolled(student, list);

	}

	@Override
	public void a_capacity(String r, Long cap) {
		env.a_capacity(r, cap);

	}

	@Override
	public boolean e_capacity(String r, Long cap) {
		// TODO Auto-generated method stub
		return env.e_capacity(r, cap);
	}

	@Override
	public void a_assign(String c, String lec, String session) {
		env.a_assign(c, lec, session);

	}

	@Override
	public boolean e_assign(String c, String lec, String session) {
		// TODO Auto-generated method stub
		return env.e_assign(c, lec, session);
	}

}
